
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/circuitplot.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:41 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Circuit Plot &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="circuitplot.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="Gates" href="gate.html" />
    <link rel="prev" title="State" href="state.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gate.html" title="Gates"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="state.html" title="State"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Circuit Plot</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.physics.quantum.circuitplot">
<span id="circuit-plot"></span><h1>Circuit Plot<a class="headerlink" href="#module-sympy.physics.quantum.circuitplot" title="Permalink to this headline">¶</a></h1>
<p>Matplotlib based plotting of quantum circuits.</p>
<p>Todo:</p>
<ul class="simple">
<li><p>Optimize printing of large circuits.</p></li>
<li><p>Get this to work with single gates.</p></li>
<li><p>Do a better job checking the form of circuits to make sure it is a Mul of
Gates.</p></li>
<li><p>Get multi-target gates plotting.</p></li>
<li><p>Get initial and final states to plot.</p></li>
<li><p>Get measurements to plot. Might need to rethink measurement as a gate
issue.</p></li>
<li><p>Get scale and figsize to be handled in a better way.</p></li>
<li><p>Write some tests/examples!</p></li>
</ul>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">CircuitPlot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nqubits</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L49-L288"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot" title="Permalink to this definition">¶</a></dt>
<dd><p>A class for managing a circuit plot.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.control_line">
<span class="sig-name descname"><span class="pre">control_line</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min_wire</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wire</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L223-L232"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.control_line" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a vertical control line.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.control_point">
<span class="sig-name descname"><span class="pre">control_point</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wire_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L234-L247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.control_point" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a control point.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.not_point">
<span class="sig-name descname"><span class="pre">not_point</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wire_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L249-L268"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.not_point" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a NOT gates as the circle with plus in the middle.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.one_qubit_box">
<span class="sig-name descname"><span class="pre">one_qubit_box</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wire_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L193-L204"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.one_qubit_box" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a box for a single qubit gate.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.swap_point">
<span class="sig-name descname"><span class="pre">swap_point</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wire_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L270-L288"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.swap_point" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a swap point as a cross.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.two_qubit_box">
<span class="sig-name descname"><span class="pre">two_qubit_box</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gate_idx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wire_idx</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L206-L221"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.two_qubit_box" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw a box for a two qubit gate. Doesn’t work yet.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CircuitPlot.update">
<span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L75-L77"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CircuitPlot.update" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the kwargs into the instance dict.</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.CreateCGate">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">CreateCGate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">latexname</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L364-L372"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.CreateCGate" title="Permalink to this definition">¶</a></dt>
<dd><p>Use a lexical closure to make a controlled gate.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.Mx">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">Mx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L347-L355"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.Mx" title="Permalink to this definition">¶</a></dt>
<dd><p>Mock-up of an x measurement gate.</p>
<p>This is in circuitplot rather than gate.py because it’s not a real
gate, it just draws one.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.Mz">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">Mz</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L337-L345"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.Mz" title="Permalink to this definition">¶</a></dt>
<dd><p>Mock-up of a z measurement gate.</p>
<p>This is in circuitplot rather than gate.py because it’s not a real
gate, it just draws one.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.circuit_plot">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">circuit_plot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nqubits</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L290-L302"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.circuit_plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Draw the circuit diagram for the circuit with nqubits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>c</strong> : circuit</p>
<blockquote>
<div><p>The circuit to plot. Should be a product of Gate instances.</p>
</div></blockquote>
<p><strong>nqubits</strong> : int</p>
<blockquote>
<div><p>The number of qubits to include in the circuit. Must be at least
as big as the largest <span class="math notranslate nohighlight">\(min_qubits\)</span> of the gates.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.quantum.circuitplot.labeller">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.quantum.circuitplot.</span></span><span class="sig-name descname"><span class="pre">labeller</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbol</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'q'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/quantum/circuitplot.py#L318-L335"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.quantum.circuitplot.labeller" title="Permalink to this definition">¶</a></dt>
<dd><p>Autogenerate labels for wires of quantum circuits.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> : int</p>
<blockquote>
<div><p>number of qubits in the circuit.</p>
</div></blockquote>
<p><strong>symbol</strong> : string</p>
<blockquote>
<div><p>A character string to precede all gate labels. E.g. ‘q_0’, ‘q_1’, etc.</p>
</div></blockquote>
<p><strong>&gt;&gt;&gt; from sympy.physics.quantum.circuitplot import labeller</strong></p>
<p><strong>&gt;&gt;&gt; labeller(2)</strong></p>
<p><strong>[‘q_1’, ‘q_0’]</strong></p>
<p><strong>&gt;&gt;&gt; labeller(3,’j’)</strong></p>
<p><strong>[‘j_2’, ‘j_1’, ‘j_0’]</strong></p>
</dd>
</dl>
</dd></dl>

</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h4>Previous topic</h4>
  <p class="topless"><a href="state.html"
                        title="previous chapter">State</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="gate.html"
                        title="next chapter">Gates</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/quantum/circuitplot.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gate.html" title="Gates"
             >next</a> |</li>
        <li class="right" >
          <a href="state.html" title="State"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Quantum Mechanics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Circuit Plot</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/quantum/circuitplot.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:41 GMT -->
</html>